// 计算歌单播放量
export const playCount = (num: number): string => {
  if (num >= 100000000) return (num / 100000000).toFixed(2) + '亿'
  else return (num / 10000).toFixed(1) + '万'
}
// 计算歌曲时长
export const formatSongTime = (milliseconds: number): string => {
  let seconds = Math.floor(milliseconds / 1000)
  let minutes = Math.floor(seconds / 60)

  seconds = seconds % 60
  minutes = minutes % 60
  const padZero = (num: number) => (num < 10 ? '0' + num : num)
  const str: string = `${padZero(minutes)}:${padZero(seconds)}`
  return str == 'NaN:NaN' ? '00:00' : str
}

// 将时长转换为秒
export const timeToSeconds = (timeString: any) => {
  // 将时间字符串按冒号和点分割成数组
  const parts = timeString.split(':')
  const secondsParts = parts[1].split('.')

  // 提取分钟、秒和毫秒
  const minutes = parseInt(parts[0], 10)
  const seconds = parseInt(secondsParts[0], 10)
  const milliseconds = parseInt(secondsParts[1], 10)

  // 计算总秒数
  const totalSeconds = minutes * 60 + seconds + milliseconds / 1000

  return totalSeconds
}
// 将时间戳转换为时间字符串
export const formatTimestamp = (timestamp: number) => {
  // 将毫秒转换为秒
  const seconds = Math.floor(timestamp / 1000);

  // 计算小时数
  const hours = Math.floor(seconds / 3600);
  // 计算剩余的秒数
  const remainingSeconds = seconds % 3600;
  // 计算分钟数
  const minutes = Math.floor(remainingSeconds / 60);
  // 计算剩余的秒数
  const finalSeconds = remainingSeconds % 60;

  // 格式化为两位数
  const paddedHours = String(hours).padStart(2, '0');
  const paddedMinutes = String(minutes).padStart(2, '0');
  const paddedSeconds = String(finalSeconds).padStart(2, '0');
  // 如果小时数为 0，则不显示小时部分
  if (hours === 0) {
    return `${paddedMinutes}:${paddedSeconds}`;
  }
  return `${paddedHours}:${paddedMinutes}:${paddedSeconds}`;
}
// 将时间戳转换为年月日 时分秒字符串格式
export const forMatToYMDTime = (timestamp: number) => {
  const date = new Date(timestamp)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  // 不足两位补0
  const paddedMonth = month < 10 ? `0${month}` : month
  const paddedDay = day < 10? `0${day}` : day
  return `${year}-${paddedMonth}-${paddedDay}`
}